<?php session_start();
include_once 'data/usercheck.php';
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title>Food Online</title>
	<link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />
</head>
<body>
  <form id="form1" method="post" action="">
  </form>
  <a href="#"></a>
  <div id="wrapper">
    <div id="logo">
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <table width="200" border="0" align="center">
    <tr>
      <td height="30"><FONT size="+6">
        <div align="center">STMS</div></td>
    </tr>
    <tr>
      <td><div align="center">STUDENT MANAGEMENT SYSTEM</div></td>
    </tr>
</table>
  <p>&nbsp;</p>
</div>
    <div id="nav">
      <div id="nav-left">
        <ul>
          <li><a href="view1.php">Home</a></li>
          <li class="orange">
            <!--div align="left"><a href="http://localhost/stms/pages/data/logout.php">Logout-</a></div-->
            <div align="left">
			<a href="http://localhost/stms/pages/data/logout.php">Logout-<?php include_once 'data/databaseconnection.php';echo $_SESSION['username'];?></a></div>
          </li>
        </ul>
      </div>
      <div id="nav-right">
        <ul>
         
           <li><a href="Aboutus.php">About us</a></li>
          <li><a href="viewhome.php">Student</a></li>
          <li><a href="Adminhome.php">Admin</a></li>
          <li><a href="http://studentmanagements.blogspot.com/">Contact</a></li>
        </ul>
      </div>
    </div>
    <div id="body">
      <div align="right">
        <table width="745" border="0">
          <tr>
            <td width="45"><font size="+1"><a href="view1.php">Show</a></font></td>
            <td width="100"><div align="left"><font size="+1"><a href="compview.php">Combination</a></font></div></td>
            <td width="60"><div align="left"><font size="+1"><a href="resultview.php">Results</a></font></div></td>
            <td width="134">&nbsp;</td>
            <td width="384"><div align="right"><font size="+1"><a href="changepass.php">changepassword</a></font></div></td>
          </tr>
        </table>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
      </div>
      <div class="clear">
		<form method="post">
		  <div align="center">
		    <table width="683" border="0">
		      <tr>
		        <td width="267"><input type="submit" name="level1G" value="Level1G"></td>
		        <td width="89"><input type="submit" name="level2G" value="Level2G"></td>
		        <td width="305"><div align="center">
		          <input type="submit" name="level3G" value="Level3G">
		        </div></td>
	          </tr>
	        </table>
		  </div>
        </form>
		
		
		
		
		  <p>&nbsp;</p>
		  <table width="719" border="0">
		    <tr>
		      <td width="232"><?php
		
		 
		  require_once 'data/databaseconnection.php';
		  
		   
		   $pass1=$_SESSION['password'];
		   $pass=md5($pass1);
		   $user=$_SESSION['username'];
				$a=mysql_query("SELECT *FROM results WHERE Regno in (SELECT Regno FROM user WHERE Password='$pass')");
					
    if (!$a) {
        die('Invalid query: ' . mysql_error());
    }
				
				$num=mysql_num_rows($a);
		//echo $num;
		//echo mysql_num_fields($a);
		
		
		/*echo "<table border=0>";
		echo "<tr>";
		
		echo "<td>Level1G</td>";
		
		echo "<td>Level2G</td>";
		echo "<td>Level3G</td>";
		echo "<tr>";
		echo "<td>";*/
		
		
		if(isset($_POST['level1G']))
		{
		echo "<table id=level1 border=0>";
		echo "<tr>";
		echo "<td>Subject</td>";
		echo "<td>Grade</td>";
		echo "<td>GPA</td>";
		for($i=0;$i<$num;$i++)
		{
		
			while($row=mysql_fetch_array($a))
			{
			
				$code=$row['SubjectCode'];
				$gra=$row['Grade'];
				$b=mysql_query("SELECT *FROM course WHERE SubjectCode='$code'");
				$c=mysql_query("SELECT *FROM grade WHERE Grade='$gra'");
			
				while($row1=mysql_fetch_array($b))
				{
				$credit[$i]=$row1['Credit'];
				
				
				
				while($row2=mysql_fetch_array($c))
				{
					
				if($row1['Level']=="1G")
				{
					
					
					$g+=$row2['GPA']*$row1['Credit'];
					echo "<tr>";
					echo "<td>".$row['SubjectCode'];
					echo "<td>".$row['Grade'];
					echo "<td>".$row2['GPA']*$row1['Credit'];
					//$g[$i]=$credit[$i]*$row2['GPA'];
				}
				
				}
			
				}
				
			}
			
			
			
			
		}
		echo "<tr>";
		echo "<td>Total GPA</td>";
		echo "<td>".$g;
		echo "</table>";
		//echo "</td>";
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		}
		?></td>
		      <td width="217">
		<?php
		if(isset($_POST['level2G']))
		{
		$a=mysql_query("SELECT *FROM results WHERE Regno in (SELECT Regno FROM user WHERE Password='$pass')");
		echo "<table id=level2 border=0>";
		echo "<tr>";
		echo "<td>Subject</td>";
		echo "<td>Grade</td>";
		echo "<td>GPA</td>";
		for($i=0;$i<$num;$i++)
		{
			while($row=mysql_fetch_array($a))
			{
				$code=$row['SubjectCode'];
				$gra=$row['Grade'];
				$b=mysql_query("SELECT *FROM course WHERE SubjectCode='$code'");
				$c=mysql_query("SELECT *FROM grade WHERE Grade='$gra'");
			
				while($row1=mysql_fetch_array($b))
				{
				while($row2=mysql_fetch_array($c))
				{
				if($row1['Level']=="2G")
				{
					
					$g+=$row2['GPA']*$row1['Credit'];
					
					echo "<tr>";
					echo "<td>".$row['SubjectCode'];
					echo "<td>".$row['Grade'];
					echo "<td>".$row2['GPA']*$row1['Credit'];
				}
				}
			
				}
			
			}
			
			
			
			
			
		}
		echo "<tr>";
		echo "<td>Total GPA</td>";
		echo "<td>".$g;
		echo "</table>";
		
		//echo "<td>";
		}
		?></td>
		      <td width="248"><?php
		if(isset($_POST['level3G']))
		{
	echo "<table id=level3 border=0>";
		echo "<tr>";
		echo "<td>Subject</td>";
		echo "<td>Grade</td>";
		echo "<td>GPA</td>";
		for($i=0;$i<$num;$i++)
		{
		
			while($row=mysql_fetch_array($a))
			{
			
				$code=$row['SubjectCode'];
				$gra=$row['Grade'];
				$b=mysql_query("SELECT *FROM course WHERE SubjectCode='$code'");
				$c=mysql_query("SELECT *FROM grade WHERE Grade='$gra'");
			
				while($row1=mysql_fetch_array($b))
				{
				while($row2=mysql_fetch_array($c))
				{
					$g=0;
				if($row1['Level']=="3G")
				{
					
					
					$g+=$row2['GPA']*$row1['Credit'];
					echo "<tr>";
					echo "<td>".$row['SubjectCode'];
					echo "<td>".$row['Grade'];
					echo "<td>".$g;
				
				}
				}
			
				}
			
			}
			
			
			
			
			
		}
		echo "<tr>";
		echo "<td>Total GPA</td>";
		echo "<td>".$g;
		echo "</table>";
		
		
		
		}
		
		
		
		
		
		
		
		
		
		
		
		//echo "</table>";
		?></td>
	        </tr>
	    </table>
		  <p>&nbsp; </p>
	    <p>&nbsp;</p>
        <p>&nbsp;</p>
      </div>
      <div id="footer">
        <ul>
          <li><a href="view1.php">Home</a> | </li>
          <li><a href="Aboutus.php">About Us</a> | </li>
          <li></li>
          <li><a href="http://studentmanagements.blogspot.com/">Contact</a></li>
        </ul>
        <p>copyright &copy;STMS Group03</p>
        <ul>
          <li></li>
        </ul>
      </div>
    </div>
  </div>
</body>
</html>
